require "yaml"

workingDir = '/cmsdata/cf/cf_program'

#puts '[info] deserializing userid hash map...'
#userMap = YAML::load_file("#{workingDir}/yaml/userIdMap_invert")
puts '[info] deserializing programid hash map...'
progMap = YAML::load_file("#{workingDir}/yaml/programIdMap_invert")

puts '[info] converting back to string...'
i=0
begin
  intSimFile = File.open("#{workingDir}/similarity_int",'r')
  stringSimFile = File.open("#{workingDir}/similarity_str.csv",'w')
  intSimFile.each_line { |line|
      arr = line.split(',')
      #stringSimFile.write(progMap[arr[0].to_i].to_s << "\t" << progMap[arr[1].to_i].to_s << "\t" << arr[2].to_s) if arr[0]!=nil && arr[1]!=nil && arr[2]!=nil # cuase very weires problem, not sure why
      stringSimFile.write("#{progMap[arr[0].to_i].to_s}\t#{progMap[arr[1].to_i].to_s}\t#{arr[2].to_s}") if arr[0]!=nil && arr[1]!=nil && arr[2]!=nil
  }
ensure
  intSimFile.close if intSimFile != nil
  stringSimFile.close if stringSimFile != nil
end

puts '[info] job done !!!'


